<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "good".
 *
 * @property int $id
 * @property int $cate_id 分类id
 * @property string $name 商品名称
 * @property string $cover 商品封面图
 * @property string $imgs 商品图片
 * @property string $video 商品视频
 * @property string $desc 商品简介
 * @property int $store 商品库存
 * @property string $price_cg 采购价
 * @property string $price_ls 零售价
 * @property int $sort 排序
 * @property int $status 状态
 * @property int $created_at 创建时间
 */
class Good extends Base
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'good';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['cate_id', 'store', 'sort', 'sale_base', 'status', 'created_at'], 'integer'],
            [['imgs', 'desc', 'video'], 'string'],
            [['price_cg', 'price_ls', 'zsd_info', 'md_info'], 'number'],
            [['name', 'unit_name', 'cover'], 'string', 'max' => 255],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'cate_id' => 'Cate ID',
            'name' => 'Name',
            'cover' => 'Cover',
            'imgs' => 'Imgs',
            'desc' => 'Desc',
            'store' => 'Store',
            'buy_type' => 'Buy Type',
            'price' => 'Price',
            'sort' => 'Sort',
            'status' => 'Status',
            'created_at' => 'Created At',
        ];
    }

    public function getGoodCate(){
        return $this->hasOne(GoodCate::class, ['id' => 'cate_id']);
    }
}
